#include "sylar/head.h"
#include <vector>

sylar::Logger::ptr g_logger = SYLAR_LOG_ROOT();

void run_in_fiber(){
    SYLAR_LOG_INFO(g_logger) << "run_in_fiber being";
    sylar::Fiber::GetThis()->back();
    SYLAR_LOG_INFO(g_logger) << "run_in_fiber end";
}

void test_fiber(){
    SYLAR_LOG_INFO(g_logger) << "main begin -1";
    {
        sylar::Fiber::GetThis();
        SYLAR_LOG_INFO(g_logger) << "main begin";
        sylar::Fiber::ptr fiber(new sylar::Fiber(run_in_fiber));
        fiber->call();
        SYLAR_LOG_INFO(g_logger) << "main after swapIn";
        fiber->call();
        SYLAR_LOG_INFO(g_logger) << "main end";
    }
    SYLAR_LOG_INFO(g_logger) << "main after end2";
}

int main(int argc, char ** argv){
    sylar::Thread::SetName("Main");
    
    std::vector<sylar::Thread::ptr> thrs;
    for(int i = 0;i < 1;++i){
        thrs.push_back(sylar::Thread::ptr(new sylar::Thread(&test_fiber, "name_" + std::to_string(i))));
    }
    for(auto i : thrs) i->join();

    return 0;
}